﻿using AutoMapper;
using MediatR;
using WMS.API.Application.Command.InventoryManagement;
using WMS.Domain.Entities.InventoryManagement;
using WMS.ErrorCode;
using WMS.Interfactructure.Interfaces;

namespace WMS.API.Application.CommandHandlers.InventoryManagement
{
    /// <summary>
    /// 库存管理-添加库存出入库请求处理类-grx
    /// </summary>
    public class AddInandoutofStorageCommandHandler : IRequestHandler<AddInandoutofStorageCommand, APIResult<int>>
    {
        private readonly IBaseRepository<InandoutofStorage> _inandoutofStorageRepository;
        private readonly IMapper _mapper;
        public AddInandoutofStorageCommandHandler(IBaseRepository<InandoutofStorage> inandoutofStorageRepository, IMapper mapper)
        {
            _inandoutofStorageRepository = inandoutofStorageRepository;
            _mapper = mapper;
        }
        /// <summary>
        ///新增库存出入库命令处理器
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns></returns>
        public async Task<APIResult<int>> Handle(AddInandoutofStorageCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>("新增库存出入库成功");
            result.Code = ResultCode.Success;

            InandoutofStorage inout = _mapper.Map<InandoutofStorage>(request);

            await _inandoutofStorageRepository.AddAsync(inout);

            return await Task.FromResult(result);
        }
    }
}
